﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Net;
using System.Xml.Linq;

namespace DataGrid
{
    public class NewsHeadLine
    {
        public string strHead { get; set; }
        public string strLine { get; set; }
        public string strDescription { get; set; }
        public string strPubDate { get; set; }
    }
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            WebClient client = new WebClient();
            Uri uri = new Uri("http://feeds.reuters.com/reuters/topNews?format=xml");
            // Beta 1: GrdHeadline.SelectionMode = DataGridSelectionMode.ExtendedFullRow;
            // Beta2:
            GrdHeadline.SelectionMode = DataGridSelectionMode.Extended;

            GrdHeadline.RowBackground = new SolidColorBrush(Colors.LightGray);
            GrdHeadline.AlternatingRowBackground = new SolidColorBrush(Colors.Yellow);
            GrdHeadline.AutoGenerateColumns = false;
            // Beta 1:GrdHeadline.ColumnWidth = 120;
            //Beta 2:
            GrdHeadline.ColumnWidth = new DataGridLength(120.0);
            GrdHeadline.RowHeight = 60;
            client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            client.DownloadStringAsync(uri);
        }




        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            // Note to reader -- the XML RSS that I used when writing appears to go down
            // from time to time. If it does, you'll likely get errors here
            // Please just rerun the app, or pull in a different RSS feed to see the results.
            XDocument xmlHeadlines = XDocument.Parse(e.Result);
            var headlines = from story in xmlHeadlines.Descendants("item")
                            select new NewsHeadLine
                            {
                                strHead = (string)story.Element("title"),
                                strLine = (string)story.Element("link"),
                                strDescription = (string)story.Element("description"),
                                strPubDate = (string)story.Element("pubDate")

                            };
            GrdHeadline.ItemsSource = headlines;
        }

        void test()
        {
            

        }
    }
}
